package com.situ.science.utils;

public class ThreadLocalUtil {
    //创建一个静态实例
    private static final ThreadLocal<Object> threadLocal = new ThreadLocal();

    //get方法获取值
    @SuppressWarnings("unchecked")//这里用了强制类型转换,用这个注解抑制这个警告
    public static <T> T get() {
        return (T) threadLocal.get();
    }
    //set方法存值
    public static void set(Object object) {
        threadLocal.set(object);
    }
    //清除ThreadLocal防止内存泄漏
    public static void remove() {
        threadLocal.remove();
    }
}


